using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DialogBase : MonoBehaviour
{
    [SerializeField]private Animator dialogAnimator;
    [SerializeField]private string introTrigger="Intro";
    [SerializeField]private string outroTrigger="Outro";
    private float waitForSeconds = 0.5f;
    public void OpenDialog()
    {
        if(!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
            dialogAnimator.SetTrigger(introTrigger);
            Debug.Log("OpenDialog");
        }
        else
        {
            dialogAnimator=GetComponent<Animator>();
            dialogAnimator.SetTrigger(outroTrigger);
        }
        
    }

    public virtual void CloseDialog()
    {
        dialogAnimator.SetTrigger(outroTrigger);
        StartCoroutine(CloseDialogCoroutine());
    }

    private IEnumerator CloseDialogCoroutine()
    {
        yield return new WaitForSecondsRealtime(waitForSeconds);
        Destroy(gameObject);
    }
}
